package data_structures;

import Utilities.Constants;

/**
 * Represents a continuous hyper-parameter.
 */
public class ContinuousHP implements HyperParameter {

	private double lowerBound;
	private double upperBound;
	private double value;

	public ContinuousHP(double lowerBound, double upperBound, double value) {
		this.lowerBound = lowerBound;
		this.upperBound = upperBound;
		this.value = value;
	}

	@Override
	public HyperParameter getRandomNeighbor() {
		double range = upperBound - lowerBound;
		double randomValue = lowerBound + Constants.RANDOM.nextDouble() * range;

		return new ContinuousHP(lowerBound, upperBound, randomValue);
	}

	/**
	 * @return the lowerBound
	 */
	public double getLowerBound() {
		return lowerBound;
	}

	/**
	 * @return the upperBound
	 */
	public double getUpperBound() {
		return upperBound;
	}

	/**
	 * @return the value
	 */
	public double getValue() {
		return value;
	}

	public boolean equals(HyperParameter hyperParameter) {
		if (hyperParameter instanceof ContinuousHP) {
			ContinuousHP rhs = (ContinuousHP) hyperParameter;
			if (this.lowerBound == rhs.getLowerBound()
					&& this.upperBound == rhs.getUpperBound()
					&& this.value == rhs.getValue()) {
				return true;
			}
		}

		return false;
	}

	public String toString() {
		String str = Double.toString(value);
		return str;
	}
}
